/*
 * @Author: Deven
 * @Email: liming@tuya.com
 * @LastEditors: Please set LastEditors
 * @FileName: &file name&
 * @Description: 
 * @Copyright: HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
 * @Company: http://www.tuya.com
 * @Date: 2020-11-07 17:16:29
 * @LastEditTime: 2022-01-25 16:30:18
 */
#ifndef _RF_MF_STACK_CFG_H__
#define _RF_MF_STACK_CFG_H__

#include "tkl_system.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef   __PACKED
  #define __PACKED                               __attribute__ ((__packed__))
#endif
#ifndef   __PACKED_STRUCT
  #define __PACKED_STRUCT                        struct __attribute__((packed, aligned(1)))
#endif
#ifndef   __PACKED_UNION
  #define __PACKED_UNION                         union __attribute__((packed, aligned(1)))
#endif


/* Definitions for error constants. */
typedef enum {
    /* No error, everything OK. */
    ERR_OK       = (INT8_T)0,
    /* Out of memory error.     */
    ERR_MEM      = (INT8_T)-1,
    /* Buffer error.            */
    ERR_BUF      = (INT8_T)-2,
    /* Timeout.                 */
    ERR_TIMEOUT  = (INT8_T)-3,
    /* Operation in progress    */
    ERR_INPROGRESS = (INT8_T)-4,
    /* Illegal value.           */
    ERR_VAL      = (INT8_T)-5,
    /* Operation would block.   */
    ERR_WOULDBLOCK = (INT8_T)-6,
    /* Address in use.          */
    ERR_USE      = (INT8_T)-7,
    /* Already connecting.      */
    ERR_ALREADY  = (INT8_T)-8,
    /* Not connected.           */
    ERR_CONN    = (INT8_T)-9,
    /* Low-level rf card error. */
    ERR_RF      = (INT8_T)-10,
    /* Illegal parameter.       */
    ERR_PARA    = (INT8_T)-11,
    /* Others error.            */
    ERR_OTHER   = (INT8_T)-12
} ERR_T;


#define MEM_ALIGNMENT           4
typedef UINT32_T                mem_ptr_t;


#ifndef MEM_ALIGN_SIZE
#define MEM_ALIGN_SIZE(size)    (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
#endif

#ifndef MEM_ALIGN
#define MEM_ALIGN(addr)         ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
#endif


#define MAX_HWADDR_LEN          8

#define ENTER_CRITICAL() \
        tkl_system_enter_critical();

#define EXIT_CRITICAL(pri) \
        tkl_system_exit_critical(pri)


#define BEACON_RF_DEBUG 0

#if BEACON_RF_DEBUG
#define TY_LOGERROR(fmt, args...) \
    tkl_dbg_printf("<%s>(%d)-: "fmt"\r\n",__FUNCTION__, __LINE__, ##args)
    
#define TY_LOGDEBUG(fmt, args...) \
    tkl_dbg_printf("<%s>(%d)-: "fmt"\r\n",__FUNCTION__, __LINE__, ##args)

#else
#define TY_LOGERROR(fmt, args...)
#define TY_LOGDEBUG(fmt, args...)
#endif


#ifdef __cplusplus
}
#endif

#endif // end _RF_MF_STACK_CFG_H__
